const { resolve } = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  //打包的入口
  entry: "./src/index.ts",
  output: {
    path: resolve(__dirname, "build"),
    filename: "js/bundle.js",
  },
  //开发模式
  mode: "development",
  //loader
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        use: "ts-loader",
      },
    ],
  },
  resolve: {
    //设置文件后缀  
    extensions: [".ts", ".tsx", ".js"], // import './test'
  }, 
  plugins: [ 
    //打包 HTML 文件
    new HtmlWebpackPlugin({
      template: "./public/index.html",
    }),
  ],
  //开发服务
  devServer: {
    //监听端口为 3000
    port: 3002,
    //自动打开浏览器
    open: true,
  },
};
